// 枚举 sex
enum Sex { Girl = 0, Boy }

// 接口 person
interface Person {
  id: number
  name: string
  sex: Sex
  age?: number
}

// 函数接口 - join
interface Join {
  regist(): boolean
  login(id: number): Person
}

// 函数接口 - exit
interface Exit {
  logout(): boolean
}

// 函数接口 - user-operate - 继承
interface UserOperate extends Person, Join, Exit {
  play(): string
}

// 类接口 
class UserPoc implements UserOperate {
  id: number
  name: string
  sex: Sex
  age?: number = 16

  constructor(user: Person) {
    this.id = user.id
    this.name = user.name
    this.sex = user.sex
    this.age = user.age

    console.log('[PocPlus] init ...');
  }

  // 新的方法
  init() {
    this.regist()
    this.login(1)
    this.play()
    this.logout()
  }

  regist() {
    console.log('[PocPlus] regist ...');
    console.table({
      id: this.id,
      name: this.name,
      sex: this.sex,
      age: this.age || 18,
    })
    return true
  }

  login(id: number) {
    console.log('[PocPlus] login ...');
    return {
      id: this.id,
      name: this.name,
      sex: this.sex,
      age: this.age,
    }
  }

  play() {
    console.log('[PocPlus] playing ...');
    return this.name + ' is played.'
  }

  logout() {
    console.log('[PocPlus] logout ...');
    return true
  }
}

// 使用
let Tom = new UserPoc({ id: 1, name: 'Bob', sex: 1 })
Tom.init()
